$(function() {



    if (method === 'detailsExc') {
        $("#pikame").PikaChoose({showCaption: false, autoPlay: false, carousel: true});
        $("#tabs").tabs({active: 0});
    }

    $('#question_form').validate({
        errorElement: "em",
        submitHandler: function(form) {

            $('#question button').attr('disabled', 'disabled');
            $("#question").mask(lang['dtl_posting_question'] + "...");
            form = $('#question_form');
            accomm_id = $('#exc_id').val();
            var serialize = form.serialize();
            $.ajax({
                url: lang_url + '/question/accom-' + accomm_id + '?' + serialize + '&ajax=true',
                method: 'get',
                success: function(data) {

                    $("#question").unmask();
                    alert(lang['dtl_posting_thanks'] + ".");
                    return false;
                }
            });
            return false;
        }
    });

    var excForm = new API.x_excForm.ExcursionsForm(enableDays, '#prices_form #nr_adults');
    excForm.Initialize();


    var x_formForm = "#prices_form";
    var x_formSelect = "#prices_form select";
    var x_formMask = ".calculation";
    var resultsHTML = {
        'nr_adults': '#nr_adults',
        'nr_childrens': '#nr_childrens',
        'check_in': '#check_in',
        'service_persons': '.service_persons',
        'service_periods': '.service_periods',
        'service_total': '.service_total',
        'total': '.total span',
        'too_many': '.too_many'
    };

    var excCalculation = new API.x_excCalculation.CalculationManager(x_formForm, x_formSelect, x_formMask, resultsHTML, API.Data.lang);
    excCalculation.Initialize();


    $("#book_now_input_default").on('click', function() {     // glavno input dugme na strani detalji unutar forme

        if (excCalculation.Data.available === 0) {
            alert(excCalculation.Data.message);
            return false;
        }

    });




    $("#book_now_input").on('click', function() {     //pomocno dugme van forme

        if (excCalculation.Data.available === 0) {

            if (method === 'detailsExc') {
                $.scrollTo('#scrool_to_price', 500);
                $("#tabs").tabs("option", "active", 1);
            } else {
                alert(excCalculation.Data.message);
                return false;
            }


        } else {
            $('#prices_form').submit();
        }

        return false;
    });

});